package iut2.client;

import iut2.shared.Troll;

import com.google.gwt.core.client.GWT;
import com.google.gwt.dom.client.Style.BorderStyle;
import com.google.gwt.dom.client.Style.Unit;
import com.google.gwt.event.dom.client.ChangeEvent;
import com.google.gwt.event.dom.client.ChangeHandler;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.text.shared.Renderer;
import com.google.gwt.uibinder.client.UiBinder;
import com.google.gwt.uibinder.client.UiField;
import com.google.gwt.user.cellview.client.CellList;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.Image;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.ListBox;
import com.google.gwt.user.client.ui.TextBox;
import com.google.gwt.user.client.ui.ValueListBox;
import com.google.gwt.user.client.ui.Widget;

public class DisplayTroll extends Composite {
	
	private static Binder uiBinder = GWT.create(Binder.class);

	  interface Binder extends UiBinder<Widget, DisplayTroll> {
	  }

	  @UiField
	  ListBox TrollRace;
	  @UiField
	  TextBox TrollName, TrollAtk, TrollDegats, TrollEsc, TrollRegen, TrollCmp1, TrollCmp2, TrollPV ;
	  @UiField
	  Button BtnMaj, BtnDel, BtnAdd;
	  @UiField 
	  Image TrollImg;
	  @UiField
	  Label LabelCmp1, LabelCmp2;
	  @UiField
	  ListBox urls;

	  private Troll Troll1;

	  public DisplayTroll() {
	    initWidget(uiBinder.createAndBindUi(this));
	    
	    // Add the categories to the list box.
	    
	    TrollRace.addItem("Skrim");
	    TrollRace.addItem("Kastar");
	    TrollRace.addItem("Durakuir");
	    TrollRace.addItem("Tomawak");
	    TrollRace.addItem("Darkling");

	    // Initialize the troll to null.
	    setTroll(null);

	    // Handle events.
	    
	    TrollRace.addChangeHandler(new ChangeHandler() {
			public void onChange(ChangeEvent event) {
				int Index = TrollRace.getSelectedIndex();
				if(TrollRace.getItemText(Index).equals("Skrim")) {
			    	  LabelCmp1.setText("Botte secr\u00E8te :");
			    	  LabelCmp2.setText("Hypnotisme :");
			      }
			      else if(TrollRace.getItemText(Index).equals("Kastar")) {
			    	  LabelCmp1.setText("Acc\u00E9l\u00E9ration m\u00E9tabolique :");
			    	  LabelCmp2.setText("Connaissance des montres :");
			      }
			      else if(TrollRace.getItemText(Index).equals("Durakuir")) {
			    	  LabelCmp1.setText("R\u00E9g\u00E9n\u00E9ration accrue :");
			    	  LabelCmp2.setText("Rafale psychique :");
			      }
			      else if(TrollRace.getItemText(Index).equals("Tomawak")) {
			    	  LabelCmp1.setText("Camouflage :");
			    	  LabelCmp2.setText("Projectile magique :");
			      }
			      else if(TrollRace.getItemText(Index).equals("Darkling")) {
			    	  LabelCmp1.setText("Balayage :");
			    	  LabelCmp2.setText("Siphon des \u00E2mes :");
			      }
			}
		}); 
	    
	  }

	  public void setTroll(Troll troll) {
	    //this.Troll1 = troll;
	    
	    BtnMaj.setEnabled(troll != null);
	    BtnDel.setEnabled(troll != null);
	    //urls.setVisible(troll == null);
	    
	    if (troll != null) {
	    	TrollName.setText(troll.getName());
	    	TrollAtk.setText(String.valueOf(troll.getAttaque()));
	    	TrollDegats.setText(String.valueOf(troll.getDegat()));
	    	TrollEsc.setText(String.valueOf(troll.getEsquive()));
	    	TrollRegen.setText(String.valueOf(troll.getRegeneration()));
	    	TrollImg.setUrl(GWT.getHostPageBaseURL() + troll.getImage_url());
	    	TrollCmp1.setText(String.valueOf(troll.getCompetence_1()));
	    	TrollCmp2.setText(String.valueOf(troll.getCompetence_2()));
	    	TrollPV.setText(String.valueOf(troll.getPtn_de_vie()));
	    	TrollImg.setWidth("150px");
	    	TrollImg.setHeight("160px");
	    	
	      if(troll.getRace().equals("Skrim")) {
	    	  TrollRace.setSelectedIndex(0);
	    	  LabelCmp1.setText("Botte secr\u00E8te :");
	    	  LabelCmp2.setText("Hypnotisme :");
	      }
	      else if(troll.getRace().equals("Kastar")) {
	    	  TrollRace.setSelectedIndex(1);
	    	  LabelCmp1.setText("Acc\u00E9l\u00E9ration m\u00E9tabolique :");
	    	  LabelCmp2.setText("Connaissance des montres :");
	      }
	      else if(troll.getRace().equals("Durakuir")) {
	    	  TrollRace.setSelectedIndex(2);
	    	  LabelCmp1.setText("R\u00E9g\u00E9n\u00E9ration accrue :");
	    	  LabelCmp2.setText("Rafale psychique :");
	      }
	      else if(troll.getRace().equals("Tomawak")) {
	    	  TrollRace.setSelectedIndex(3);
	    	  LabelCmp1.setText("Camouflage :");
	    	  LabelCmp2.setText("Projectile magique :");
	      }
	      else if(troll.getRace().equals("Darkling")) {
	    	  TrollRace.setSelectedIndex(4);
	    	  LabelCmp1.setText("Balayage :");
	    	  LabelCmp2.setText("Siphon des \u00E2mes :");
	      }
	   }
	}
}
